package com.zmn.plat.services.impl.product.tariff.item.city.price;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import com.zmn.plat.common.dto.price.ItemTo;
import com.zmn.plat.model.entity.product.tariff.item.ProductItemQuery;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.zmn.plat.model.entity.product.tariff.item.city.price.ProductTariffItemCityPrice;
import com.zmn.plat.model.entity.product.tariff.item.city.price.ProductTariffItemCityPriceQuery;
import com.zmn.plat.persistence.interfaces.product.tariff.item.city.price.ProductTariffItemCityPriceDao;
import com.zmn.plat.services.interfaces.product.tariff.item.city.price.ProductTariffItemCityPriceService;

@Service
public class ProductTariffItemCityPriceServiceImpl implements ProductTariffItemCityPriceService {

    @Resource
    ProductTariffItemCityPriceDao productFaultItemCityPriceDao;

    @Override
    public ProductTariffItemCityPrice findByKey(Integer relateId) {
        return productFaultItemCityPriceDao.findByKey(relateId);
    }

    @Override
    public List<ProductTariffItemCityPrice> listPageByQuery(ProductTariffItemCityPriceQuery query) {
        int count = countByQuery(query);
        query.setTotalCount(count);
        return productFaultItemCityPriceDao.listPageByQuery(query);
    }

    @Override
    public List<ProductTariffItemCityPrice> listByQuery(ProductTariffItemCityPriceQuery query) {
        return productFaultItemCityPriceDao.listByQuery(query);
    }

    @Override
    public List<ProductTariffItemCityPrice> listPrice(ProductTariffItemCityPriceQuery query) {
        return productFaultItemCityPriceDao.listPrice(query);
    }

    @Override
    public List<ProductTariffItemCityPrice> listAll() {
        return productFaultItemCityPriceDao.listAll();
    }

    @Override
    public List<ProductTariffItemCityPrice> listByGroupIds(List<Integer> faultGroupIds) {
        return productFaultItemCityPriceDao.listByGroupIds(faultGroupIds);
    }

    @Override
    public Integer countByQuery(ProductTariffItemCityPriceQuery query) {
        return productFaultItemCityPriceDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(ProductTariffItemCityPrice faultItemCityPrice) {
        return productFaultItemCityPriceDao.updateByKey(faultItemCityPrice);
    }

    @Override
    public Integer insert(ProductTariffItemCityPrice faultItemCityPrice) {
        return productFaultItemCityPriceDao.insert(faultItemCityPrice);
    }

    @Override
    public Integer insertBatch(List<ProductTariffItemCityPrice> itemCityPriceList) {
        return productFaultItemCityPriceDao.insertBatch(itemCityPriceList);
    }

    @Override
    public void updateBatch(List<Integer> updateIdList, Integer priceStandard, Integer price, Integer internalSettlementPrice, Integer externalSettlementPrice, Integer negotiableMaxPrice,
        Integer negotiableMinPrice, String opertor, Date updateTime) {
        productFaultItemCityPriceDao.updateBatch(updateIdList, priceStandard, price, internalSettlementPrice, externalSettlementPrice, negotiableMaxPrice, negotiableMinPrice, opertor, updateTime);
    }

    @Override
    public Integer deleteByKey(Integer relateId) {
        return productFaultItemCityPriceDao.deleteByKey(relateId);
    }

    @Override
    public Integer deleteByGroupIds(List<Integer> faultGroupIds) {
        return productFaultItemCityPriceDao.deleteByGroupIds(faultGroupIds);
    }

    @Override
    public Integer deleteByProductIdAndTarifIdAndItemId(Integer productId, Integer tariffId, Integer itemId) {
        return productFaultItemCityPriceDao.deleteByProductIdAndTarifIdAndItemId(productId, tariffId, itemId);
    }

    @Override
    public Integer deleteByProductIdAndTarifIdAndItemIds(Integer productId, Integer tariffId, List<Integer> itemIds) {
        return productFaultItemCityPriceDao.deleteByProductIdAndTarifIdAndItemIds(productId, tariffId, itemIds);
    }

    @Override
    public Integer deleteByProductIdAndTarifIdAndGroupIds(Integer productId, Integer tariffId, List<Integer> groupIds) {
        return productFaultItemCityPriceDao.deleteByProductIdAndTarifIdAndGroupIds(productId, tariffId, groupIds);
    }

    @Override
    public Integer deleteByCityGroupIdsAndItemIdAndProductId(List<Integer> groupIds, Integer itemId, Integer productId, Integer tariffId) {
        return productFaultItemCityPriceDao.deleteByCityGroupIdsAndItemIdAndProductId(groupIds, itemId, productId, tariffId);
    }


    /********************************* 重构时直接使用 ************************************************/

    @Override
    @Cacheable(cacheNames = "redis10m", key = "'price:city:listItemPriceByQuery:ProductItemQuery:'+#p0", unless = "#result == null")
    public List<ItemTo> listItemPriceByQuery(ProductItemQuery query) {
        return productFaultItemCityPriceDao.listItemPriceByQuery(query);
    }
}